#!/usr/bin/env python
# -*- coding:utf-8 -*-

import sys
import simplejson as json

from PySide import QtCore, QtGui

import kanboxsettings

from qui.settings import *

class Settings(QtGui.QMainWindow):
    '''
    Main Window
    '''
    def __init__(self, parent=None):
        super(Settings, self).__init__(parent)
        self.ui = Ui_Dialog()
        self.ui.setupUi(self)
        
        self.ui.toolButtonDir.clicked.connect(self._selDir)
        
        if 'RootPath' in kanboxsettings.Settings:
            self.ui.lineEditPath.setText(kanboxsettings.Settings['RootPath'])
            print kanboxsettings.Settings['RootPath']
        
    def _selDir(self):
        dir = QtGui.QFileDialog.getExistingDirectory(self, u"Firmware", QtCore.QDir.currentPath())
        print dir
        if dir:
            self.ui.lineEditPath.setText(dir)
            with open('config', 'w') as f:
                kanboxsettings.Settings['RootPath'] = dir
                json.dump(kanboxsettings.Settings, f)

if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    win = Settings()
    win.show()
    sys.exit(app.exec_())  
